# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=dsfmt
_pkgname=dSFMT
pkgver=2.2.3
pkgrel=1
pkgdesc="Double precision SIMD-oriented Fast Mersenne Twister"
url="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/#dSFMT"
arch="all"
license="BSD-3-Clause"
depends=""
makedepends=""
subpackages="$pkgname-dev"
source="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/$_pkgname-src-$pkgver.tar.gz
	$pkgname.pc
	0001-dSFMT.patch
	"
builddir="$srcdir/$_pkgname-src-$pkgver"

_soname="lib$_pkgname.so"

prepare() {
	cd "$builddir"

	sed "s/@VERSION@/$pkgver/" "$srcdir"/$pkgname.pc > $pkgname.pc || return 1
	default_prepare
}

build() {
	cd "$builddir"

	# copied from https://github.com/JuliaLang/julia/blob/master/deps/dsfmt.mk
	local cflags="$CFLAGS -DNDEBUG -DDSFMT_MEXP=19937 -DDSFMT_DO_NOT_USE_OLD_NAMES
		-fPIC -O3 -finline-functions -fomit-frame-pointer
		-fno-strict-aliasing --param max-inline-insns-single=1800
		-Wmissing-prototypes -Wall -std=c99 -shared"

	if [ "$CARCH" = x86_64 ]; then
		cflags="$cflags -msse2 -DHAVE_SSE2"
	fi

	gcc $cflags dSFMT.c -o $_soname
}

package() {
	cd "$builddir"

	install -D $_soname "$pkgdir"/usr/lib/$_soname || return 1
	install -D dSFMT.h "$pkgdir"/usr/include/dSFMT.h || return 1
	install -D $pkgname.pc "$pkgdir"/usr/lib/pkgconfig/$pkgname.pc
}

sha512sums="6d8ddcd01aab3f9039f4f0288a8af53e290cc2f293ed8c4a8c9f3b3f12398e7eedfce8016117b425766ba89c61c86c13b3e420035b5f9bf91315b8b814c03662  dSFMT-src-2.2.3.tar.gz
07810381fea8477478a968aaeca983ef639dd42ee0efccf7bdc910d137b07f55c43f3feb1ee59eaf97f4143ac273e32a02f557cb3a0d4e430480f650efee4fbd  dsfmt.pc
9feac5b96e431d110e88631e5540cec1e8ce3443c0c74afd8132650a077ae569e0214bbee9326d4f8a91e8fc10603fdcceedebbc3713bf0c3713117906b1f6da  0001-dSFMT.patch"
